var Dog = require('./dog.js')
var dog1 = new Dog('taidi',4)
var dog2 = new Dog('zangao',8)
dog1.on('bark',function(){
    /*var i = dog1.energy;
    for(i; i >= 0; i--){
        dog1.bark();
        dog1.energy--;
    }*/
    //dog1.bark();
    console.log(this.name+" barked! energy: "+this.energy)

})
dog2.on('bark',function(){
    /*var i = dog2.energy;
    for(i; i >= 0; i--){
        dog2.bark();
        dog2.energy--;
    }*/
    //dog2.bark();
    console.log(this.name+" barked! energy: "+this.energy)
})
// const dog1Bark = setInterval(function(){
//     dog1.emit('bark');
//     if(dog1.energy<0){
//         clearInterval(dog1Bark);
//     }
// }, 1000);
// var dog2Bark = setInterval(function(){
//     dog2.emit('bark');
//     if(dog2.energy<0){
//         clearInterval(dog2Bark);
//     }
// }, 1000);


